﻿@model LynxWiki.ViewModels.TopicVersionViewData

@using LynxWiki.ViewModels;

@{
    ViewBag.Title = "Edit";
    Layout = "~/Views/Shared/_LayoutTopic.cshtml";
}

@Html.Partial("_TopicDisplayName", new TopicDisplayName { DisplayName = Model.TopicName })
@using (Html.BeginForm("EditDiscussion", "TopicDiscussion", FormMethod.Post, new { id = "frmEditTopic" })) {
   @Html.TextAreaFor(model => model.Topic.WikiText, new { @class = "editBody" })
    @Html.LabelFor(model => model.Tags)<div id="ErrorMsgDiv" ></div>
     @Html.TextAreaFor(model => model.Tags)
    if (Convert.ToBoolean(ViewBag.CaptchaSetting)) {
        <br /> @Html.LabelFor(model => model.CaptchaInput)<img alt="Captcha" src="@Url.Action("CaptchaImage", "WikiTopic", new { prefix = "Discussion" })" />
    <div class="editor-field">
    @Html.EditorFor(model => model.CaptchaInput) 
    @Html.ValidationMessageFor(model => model.CaptchaInput)</div>
    }
    <input type="submit" name="btnNewVersion" id="btnNewVersion" value="New Version" />
    <input type="submit" name="btnMinorUpdate" id="btnMinorUpdate" value="Minor Update" />
    <input type="submit" name="btnPreview" id="btnPreview" value="Preview" /><br />
    <div><a id="slick-toggle_minor" href="#">@Html.Label("Minor Update Details")</a>
    <div id="slickbox_minor">@Html.TextAreaFor(model => model.MinorUpdateDetails)<br />
    @Html.LabelFor(model => model.MinorUpdate)<br />
    @Html.TextAreaFor(model => model.MinorUpdate)<br /></div></div>
    <div><a id="slick-toggle_privs" href="#">Manage Privileges</a>
    <div id="slickbox_privs">@Html.LabelFor(model => model.Topic.AllowUpdatePrivsUser)<br />
    @Html.TextBoxFor(model => model.ListAllowEditUser)<br />
    @Html.LabelFor(model => model.Topic.AllowUpdatePrivsRole)<br />
    @Html.TextBoxFor(model => model.ListAllowEditRole)<br />
    @Html.LabelFor(model => model.Topic.DenyReadPrivsUser)<br />
    @Html.TextBoxFor(model => model.ListDenyReadUser)<br />
    @Html.LabelFor(model => model.Topic.DenyReadPrivsRole)<br />
    @Html.TextBoxFor(model => model.ListDenyReadRole)<br /></div></div>
    @Html.HiddenFor(model => model.PagePath)
    @Html.HiddenFor(model => model.TopicName)
    @Html.HiddenFor(model => model.Topic.Version)
    @Html.Hidden("User", (string)ViewBag.User)
}
@section Scripts {
    <script type="text/javascript" >
        $(document).ready(function () {
            $("#btnPreview").click(function (e) {
                $("#frmEditTopic").attr("target", "_blank");
                return true;
            });
            $("#btnNewVersion").click(function (e) {
                $("#frmEditTopic").attr("target", "_self");
                return true;
            });
            $("#btnMinorUpdate").click(function (e) {
                if ($('#MinorUpdate').val()) {
                    $("#frmEditTopic").attr("target", "_self");
                    return true;
                }
                else {
                    $('#ErrorMsgDiv').text('Minor Update must not be null');
                    $('#ErrorMsgDiv').show();
                    return false;
                }
            });
            $('#slickbox_minor').hide();
            $('#slick-toggle_minor').click(function () {
                $('#slickbox_minor').toggle(400);
                return false;
            });
            $('#ErrorMsgDiv').hide();
            $('#slickbox_privs').hide();
            $('#slick-toggle_privs').click(function () {
                $('#slickbox_privs').toggle(400);
                return false;
            });
        });
    </script>
}
